package com.mc.moring.main;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.mc.moring.R;
import com.mc.moring.app.LogUtils;
import com.mc.moring.base.BaseActivity;
import com.mc.moring.bean.MyTradeListBean;
import com.mc.moring.util.GsonUtils;
import com.mc.moring.util.PointMgr;
import com.mc.moring.util.StringUtils;
import com.mc.moring.util.TimeUtils;

public class MyTradesDetailsActivity extends BaseActivity {
    private ImageButton abBackIBtn;
    private TextView abTitleTV;
    private MyTradeListBean.dataBean bean;
    private TextView tv_1, tv_2, tv_3, tv_4, tv_5, tv_6, tv_trade_detail_account;
    private TextView title1, title4;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        PointMgr.INSTANCE.sendEvent("cl_person_infoof-10_open");
        Log.e("PointMgr.INSTANCE.sendEvent", "cl_person_infoof-10_open");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tradle_details);
        bean = (MyTradeListBean.dataBean) getIntent().getSerializableExtra("_bean");
        LogUtils.logE(GsonUtils.INSTANCE.getGson().toJson(bean));
        abBackIBtn = findViewById(R.id.abBackIBtn);
        abTitleTV = findViewById(R.id.abTitleTV);
        tv_1 = findViewById(R.id.tv_1);
        title1 = findViewById(R.id.tv_title1);
        tv_2 = findViewById(R.id.tv_2);
        tv_3 = findViewById(R.id.tv_3);
        tv_4 = findViewById(R.id.tv_4);
        title4 = findViewById(R.id.tv_title4);
        tv_5 = findViewById(R.id.tv_5);
        tv_6 = findViewById(R.id.tv_6);
        tv_trade_detail_account = findViewById(R.id.tv_trade_detail_account);
        abTitleTV.setText("Detalles");
        abBackIBtn.setOnClickListener(v -> finish());
        Log.e("----bean.getTransStatus()",bean.getTransNo());
        tv_1.setText(bean.getTransNo());
        Log.e("----bean.getReqTransType()",bean.getReqTransType());
        Log.e("----bean.getSendAccount()",bean.getSendAccount());
        Log.e("----bean.getReceiveAccount()",bean.getReceiveAccount());
        if (bean.getReqTransType().equals("OL")) {
            tv_2.setText("Pago");
            tv_trade_detail_account.setText("Cuenta");
            tv_5.setText(bean.getReceiveAccount());
        } else if (bean.getReqTransType().equals("LA")) {
            tv_2.setText("Préstamo");
            tv_trade_detail_account.setText("Cuenta beneficiaria");
            tv_5.setText(bean.getReceiveAccount());
        }
        Log.e("----bean.getTransStatus()",bean.getTransStatus());
        if (bean.getTransStatus().equals("S")) {
            tv_3.setText("Éxito");
        } else if (bean.getTransStatus().equals("F")) {
            tv_3.setText("Fracaso");
        } else {
            tv_3.setText("Procesando");
        }

        Log.e("----bean.getTransTime()",bean.getTransTime());
        tv_4.setText(TimeUtils.date2TradeDetailFormatDate(bean.getTransTime()));

        Log.e("----bean.getTransAmount()",bean.getTransAmount());
        tv_6.setText("$" + StringUtils.formatNumberWithCommas(bean.getTransAmount()));
    }

    @Override
    public Activity getActivity() {
        return null;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus){
        super.onWindowFocusChanged(hasFocus);
        int right = tv_2.getRight();
        if ( tv_1.getLeft() < title1.getRight() ){
            title1.setText("Folio de \ntransacción");
            tv_1.setRight(right);
        }
        if ( tv_4.getLeft() < title4.getRight() ){
            title4.setText("Tiempo de \ntransferencia");
            tv_4.setRight(right);
        }
        if ( tv_trade_detail_account.getText() == "Cuenta beneficiaria" ){
            if ( tv_5.getLeft() < tv_trade_detail_account.getRight() ){
                tv_trade_detail_account.setText("Cuenta \nbeneficiaria");
                tv_5.setRight(right);
            }
        }
    }
}
